<?php
function google_map_location_enterprise_list_location_form(){
  module_load_include('inc', 'google_map_location','google_map_location');
  $items = load_gmap_location_all();
  $locations = array();
  foreach($items as $item){
    $locations[$item['lid']]=$item['title'];
  }
  $form['locations'] = array(
    '#type' => 'checkboxes',
    '#options' => $locations,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Delete'),
	'#submit' =>array('google_map_location_enterprise_delete_submit'),
  );
  $form['edit'] = array(
    '#type' => 'submit',
    '#value' => t('Edit'),
	'#submit' =>array('google_map_location_enterprise_edit_submit'),
  );
  return $form;
}
function google_map_location_enterprise_edit_submit($form, &$form_state){
  $locations = array_filter($form_state['values']['locations']);
  if(isset($locations)&& is_array($locations) && !empty($locations)){
    $id = array_shift($locations);
    $form_state['redirect'] ='google_map_location_setting/google_map_location_options_edit/'.$id;
  }
}
function google_map_location_enterprise_delete_submit($form, &$form_state){
  module_load_include('inc', 'google_map_location','google_map_location');
  $locations = array_filter($form_state['values']['locations']);
  foreach($locations as $location){
    delete_location($location);
  }
  drupal_set_message(t('You configuration have been saved!'));
}
function theme_google_map_location_enterprise_list_location_form($form){
  $options = array(
    'key' => variable_get('GOOGLE_KEY',GOOGLE_KEY),
    'center_x' => variable_get('GOOGLE_CENTER_X',GOOGLE_CENTER_X),
    'center_y' => variable_get('GOOGLE_CENTER_Y',GOOGLE_CENTER_Y),
    'map_width' => variable_get('GOOGLE_MAP_WIDTH',GOOGLE_MAP_WIDTH),
    'map_height' => variable_get('GOOGLE_MAP_HEIGTH',GOOGLE_MAP_HEIGTH),
    'zoom' => variable_get('GOOGLE_ZOOM',GOOGLE_ZOOM),
    'items' => load_gmap_location_options(),
  );
  $output = drupal_render($form['submit']);
  $output.= drupal_render($form['edit']);
  $output.= '<table><tr><td valign="top" >';
  if (isset($form['locations']) && is_array($form['locations'])) {
    foreach (element_children($form['locations']) as $key) {
      $output.= drupal_render($form['locations'][$key]);
    }
  }
  $output.= '</td><td>';
  $output.= theme('google_map_location_list', $options);
  $output.= '</td></tr></table>';
  $output.= drupal_render($form);
  return $output;
}

?>